using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System.Xml.Serialization;
using System.IO.IsolatedStorage;
using System.IO;
using BattleCity.Rendering;
using BattleCity.GameLogic.Xml;

namespace BattleCity
{
    public class ScoresMenu
    {
        String[] names;
        String[] scores;

        Vector2[] namePositions;
        Vector2[] scoresPositions;
        Vector2 menuWrapperPosition;
    

        SpriteFont menuFont;
        Texture2D menuWrapper;
        
       
        SpriteBatch spriteBatch;
       

        ContentManager content;

        Vector2 screenCenter;

        int buttonX;

        public ScoresMenu(Vector2 screenCenter, SpriteFont menuFont, Texture2D menuWrapper, SpriteBatch spriteBatch, ContentManager content)
        {
            this.menuWrapper = menuWrapper;
            this.menuFont = menuFont;
            this.spriteBatch = spriteBatch;
            this.content = content;
            this.screenCenter = screenCenter;

            #if WINDOWS_PHONE 
            menuWrapperPosition = new Vector2(screenCenter.X - 200, 0.0f);
            #else
            menuWrapperPosition = new Vector2(screenCenter.X - 300, 0.0f);
            #endif

            names = new string[10];
            namePositions = new Vector2[10];

            scores = new string[10];
            scoresPositions = new Vector2[10];

            for (int i = 0; i < 10; ++i)
            {
                names[i] = "";
                scores[i] = "";
                namePositions[i] = new Vector2(screenCenter.X - 170, 10 + i * 45);
                scoresPositions[i] = new Vector2(screenCenter.X + 150, 10 + i * 45);
            }


            for (int i = 0; i < Scores.savedScores.scores.Count; ++i)
            {
                names[i] = Scores.savedScores.scores[i].name;
                scores[i] = Scores.savedScores.scores[i].completedLevels.ToString();
                if (Scores.savedScores.scores[i].completedLevels > 999) scores[i] = "999";
                scoresPositions[i] = new Vector2(screenCenter.X + 170 - menuFont.MeasureString(scores[i]).X, 10 + (i * 45));
            }

            if (Scores.savedScores.scores.Count == 0)
            {
                names[4] = "NO SCORES";
                names[5] = "AVAILABLE";
                namePositions[4] = new Vector2(screenCenter.X - menuFont.MeasureString(names[4]).X * 0.5f, 10 + 4 * 45);
                namePositions[5] = new Vector2(screenCenter.X - menuFont.MeasureString(names[5]).X * 0.5f, 10 + 5 * 45);
            }


        }

        public void Update(Vector2 gsPosition, ref MenuStates menuState)
        {
            
        }

        public void Draw()
        {
            spriteBatch.Draw(menuWrapper, menuWrapperPosition, Color.White);

            if (Scores.savedScores.scores.Count == 0)
            {
                spriteBatch.DrawString(menuFont, names[4], namePositions[4], Color.Green);
                spriteBatch.DrawString(menuFont, names[5], namePositions[5], Color.Green);
            }
            else
            {
                for (int i = 0; i < 10; ++i)
                {
                    spriteBatch.DrawString(menuFont, names[i], namePositions[i], Color.Green);
                    spriteBatch.DrawString(menuFont, scores[i], scoresPositions[i], Color.DarkCyan);

                }
            }
        }
    }
}